<template>
  <div id="app">
    <div style="padding: 100;">
      <span style="color: aqua;">欢迎来到蜗牛学院</span>
      <el-button type="primary" @click="exitLogin" style="float: right;">退出登录</el-button>
    </div>
    <el-row>
      <el-col :span="4">
        <div>
          <el-menu v-for="(menus,index) in menusData" :key="index" @select="selectNav" default-active="2" class="el-menu-vertical-demo">
            <el-submenu v-if="menus.menusType==0" :index="index+''">
              <template slot="title">
                <i v-if="menus.menusIcon!=null" :class="menus.menusIcon"></i>
                <span>{{menus.menusName}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item v-for="(menusNext,nextIndex) in menus.menusDtos" :key="nextIndex" :index="menusNext.menusRouter">
                  <i v-if="menusNext.menusIcon!=null" :class="menusNext.menusIcon"></i>
                  <span>{{menusNext.menusName}}</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-menu-item v-if="menus.menusType==1" :index="menus.menusRouter">
              <i v-if="menus.menusIcon!=null" :class="menus.menusIcon"></i>
              <span>{{menus.menusName}}</span>
            </el-menu-item>
          </el-menu>
        </div>
      </el-col>
      <el-col :span="20">
        <div class="main-content">
          <router-view></router-view>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'Main',
  data(){
    return {
      account:null,
      menusData:[]
    }
  },
  methods:{
    selectNav(index){
      console.log(index);
      this.$router.push(index);
    },
    loadAccountMenus(){
      let accountJson=localStorage.getItem("account");
      this.account=JSON.parse(accountJson);
      this.$http.get("/menus/findMenusByAccount/"+this.account.data.accountId).then(resp=>{
        if(resp.data.code==200){
          this.menusData=resp.data.data;
        }
      })
    },
    exitLogin(){
      this.$http.get("/logout")
    }
  },
  created() {
    this.loadAccountMenus();
  }
}
</script>

<style scoped>

</style>